package com.ruoyi.hr.service.impl.changemanage.virtualorganize;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.hr.mapper.changemanage.virtualorganize.VirtualOrganizeMapper;
import com.ruoyi.hr.service.changemanage.virtualorganize.VirtualOrganizeService;
import com.ruoyi.hr.util.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author yuanwei
 * @explain 员工虚拟组织管理
 * @date 2020/4/20
 */
@Service
public class VirtualOrganizeServiceImpl implements VirtualOrganizeService {

    @Autowired
    private VirtualOrganizeMapper virtualOrganizeMapper;

    //加入
    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findVirtualJoinList(Map<String, Object> map) {
        return virtualOrganizeMapper.findVirtualJoinList(utils.addAuthority(map));
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public Map<String, Object> findVirtualJoin(String id) {
        return virtualOrganizeMapper.findVirtualJoin(id);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int updateVirtualJoin(Map<String, Object> map) {
        return virtualOrganizeMapper.updateVirtualJoin(map);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findVirtualDep() {
        return virtualOrganizeMapper.findVirtualDep();
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findVirtualJob() {
        return virtualOrganizeMapper.findVirtualJob();
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int removeVirtualJoin(String ids) {
        String[] idSplit = ids.split(",");
        int num = 0;
        for (String id : idSplit) {
            int count = virtualOrganizeMapper.getJoinCheck(id);
            if (count > 0) {
                return 0;
            }
            num = virtualOrganizeMapper.removeJoin(id);
            if (num == 0) {
                return 0;
            }
        }
        return num;
    }

    //退出
    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findVirtualQuitList(Map<String, Object> map) {
        return virtualOrganizeMapper.findVirtualQuitList(utils.addAuthority(map));
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findVirtualJoinPersonList(Map<String, Object> map) {
        return virtualOrganizeMapper.findVirtualJoinPersonList(utils.addAuthority(map));
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public Map<String, Object> findVirtualQuit(String id) {
        return virtualOrganizeMapper.findVirtualQuit(id);
    }

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public int updateVirtualQuit(Map<String, Object> map) {
        return virtualOrganizeMapper.updateVirtualQuit(map);
    }

    //历史
    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<Map<String, Object>> findVirtualHistoryList(Map<String, Object> map) {
        return virtualOrganizeMapper.findVirtualHistoryList(utils.addAuthority(map));
    }
}
